import { list } from "../../api/manager";

Component({
    lifetimes: {
      created() {
          this.getList()
      }
    },

    properties: {
      noDataImg: {
        type: String,
        value: '',
      },
      noDataText: {
        type: String,
        value: '暂无数据',
      },
      loading: {
        type: Boolean,
        value: false,
      },
    },

    data: {
        val:'',
        options:[],
        ifShow:false,
        maxlength:'20',
        inputMaxlength:'20',
        placeholder:'点击选择客户经理',
        keyword:'',
        setDefault:true
    },

    methods: {
      bindfocus(){
        this.data.ifShow = true 
        this.setData({
          ifShow:this.data.ifShow,
        })
      },
      changeInput(e){
        this.data.keyword =  e.detail.value
        this.data.ifShow = true 
        this.setData({
          ifShow:this.data.ifShow,
          keyword:this.data.keyword
        })
        this.getList()
      },
      choosePeople(e){
        this.data.val =  e.currentTarget.dataset.item.name
        this.data.ifShow = false 
        this.setData({
          ifShow: this.data.ifShow,
          val:this.data.val
        })
        this.triggerEvent("setAccoManager", e.currentTarget.dataset.item)
      },
      getList(){
        let params = {
          keyword:this.data.keyword
        }
        list(params).then(res=>{
            this.data.options = res.data.data
            this.setData({
                options: this.data.options
            })
            if(res.data.data.length > 0 && this.data.setDefault == true){
              this.triggerEvent("setAccoManager", res.data.data[0])
              this.data.val = res.data.data[0].name
              this.data.setDefault = false
              this.setData({
                setDefault:this.data.setDefault,
                val:this.data.val
              })
            }
        })
      },
    }
  })
  